// 抽象基类 Graph
abstract class Graph {
    protected double centerX; // 中心点横坐标
    protected double centerY; // 中心点纵坐标
    
    // 构造方法
    public Graph(double centerX, double centerY) {
        this.centerX = centerX;
        this.centerY = centerY;
    }
    
    // 修改中心坐标的方法
    public void setCenter(double centerX, double centerY) {
        this.centerX = centerX;
        this.centerY = centerY;
    }
    
    // 计算面积的抽象方法
    public abstract double calculateArea();
    
    // 计算周长的抽象方法
    public abstract double calculatePerimeter();
}

// 派生类 Square（正方形）
class Square extends Graph {
    private double sideLength; // 边长
    
    // 构造方法
    public Square(double centerX, double centerY, double sideLength) {
        super(centerX, centerY);
        this.sideLength = sideLength;
    }
    
    // 计算面积
    public double calculateArea() {
        return sideLength * sideLength;
    }
    
    // 计算周长
    public double calculatePerimeter() {
        return 4 * sideLength;
    }
}

// 派生类 Circle（圆）
class Circle extends Graph {
    private double radius; // 半径
    
    // 构造方法
    public Circle(double centerX, double centerY, double radius) {
        super(centerX, centerY);
        this.radius = radius;
    }
    
    // 计算面积
    public double calculateArea() {
        return Math.PI * radius * radius;
    }
    
    // 计算周长
    public double calculatePerimeter() {
        return 2 * Math.PI * radius;
    }
}

// 派生类 Rectangle（长方形）
class Rectangle extends Graph {
    private double length; // 长
    private double width; // 宽
    
    // 构造方法
    public Rectangle(double centerX, double centerY, double length, double width) {
        super(centerX, centerY);
        this.length = length;
        this.width = width;
    }
    
    // 计算面积
    public double calculateArea() {
        return length * width;
    }
    
    // 计算周长
    public double calculatePerimeter() {
        return 2 * (length + width);
    }
}

// 派生类 Ellipse（椭圆）
class Ellipse extends Graph {
    private double semiMajorAxis; // 长半轴
    private double semiMinorAxis; // 短半轴
    
    // 构造方法
    public Ellipse(double centerX, double centerY, double semiMajorAxis, double semiMinorAxis) {
        super(centerX, centerY);
        this.semiMajorAxis = semiMajorAxis;
        this.semiMinorAxis = semiMinorAxis;
    }
    
    // 计算面积
    public double calculateArea() {
        return Math.PI * semiMajorAxis * semiMinorAxis;
    }
    
    // 计算周长（近似值）
    public double calculatePerimeter() {
        return Math.PI * (3 * (semiMajorAxis + semiMinorAxis) - Math.sqrt((3 * semiMajorAxis + semiMinorAxis) * (semiMajorAxis + 3 * semiMinorAxis)));
    }
}

public class Main {
    public static void main(String[] args) {
        // 创建一个正方形对象
        Square square = new Square(0, 0, 5);
        System.out.println("正方形面积: " + square.calculateArea());
        System.out.println("正方形周长: " + square.calculatePerimeter());

        // 创建一个圆形对象
        Circle circle = new Circle(0, 0, 3);
        System.out.println("圆形面积: " + circle.calculateArea());
        System.out.println("圆形周长: " + circle.calculatePerimeter());

        // 创建一个长方形对象
        Rectangle rectangle = new Rectangle(0, 0, 4, 6);
        System.out.println("长方形面积: " + rectangle.calculateArea());
        System.out.println("长方形周长: " + rectangle.calculatePerimeter());

        // 创建一个椭圆对象
        Ellipse ellipse = new Ellipse(0, 0, 5, 3);
        System.out.println("椭圆面积: " + ellipse.calculateArea());
        System.out.println("椭圆周长: " + ellipse.calculatePerimeter());
    }

}
